/*
                  Snake Class Definition
*/

#ifndef WORM_H
#define WORM_H

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <vector>
#include <string>
#include <iostream>

#include "Point.h"
#include "NetworkDefinitions.h"
#include "Mapping/Map.h"
#include "Functions.h"

using namespace std;

enum NodeType { BLANK = -1, HEAD, BODY, TAIL };

struct BodyNode
{
    BodyNode()
    {
        Type = BLANK;
    }

    BodyNode(NodeType NewType, Point NewPosition)
    {
        Type = NewType;
        Position = NewPosition;
    }

    NodeType Type;
    Point Position;
};

class Snake
{
    public:
        Snake();
        ~Snake();

        int Initialise(Point Position, int iNewWidth, int iNewHeight, int iNewDirection, int iSize);

        int Reset(Point Position, int iNewDirection, int iSize);

        // Add a section to the end of the worm
        void AddSection();

        // Move the worm
        void Move(Map& currentMap);

        void setDirection(int iNewDirection);
        int getDirection();

        void Draw(SDL_Surface *surface);

        int getSize();

        int getHeight();
        int getWidth();

        int getSpeed();
        void setSpeed(const int& iNewSpeed);

        bool CanMove(const int& iFrameTime);

        Point getPosition();

        vector<BodyNode*> Body;

    private:
        int iDirection;
        int iWidth, iHeight;
        bool bMoving;

        int iSpeed; //  how many milliseconds between moves
        int iTimePassed;

        SDL_Surface *Node;
};

#endif
